package com.cai.config;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * @author RuoLi
 * 用户在新监听器
 */
@WebListener
public class OnlineUserBindingListener implements HttpSessionListener{
    private static  int onlinePerson=0;
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        onlinePerson++;
        HttpSession session= se.getSession();
        ServletContext application=session.getServletContext();
        application.setAttribute("onlinePerson",onlinePerson);

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        onlinePerson--;
        HttpSession session= se.getSession();
        ServletContext application=session.getServletContext();
        application.setAttribute("onlinePerson",onlinePerson);
    }
}
